##### My (demuredemeanor) tmux config, a work in progress
# Uses tabstop=4; shiftwidth=4 tabs; foldmarker={{{,}}};
# https://notabug.org/demure/dotfiles/
# legacy repo http://github.com/demure/dotfiles
#
# Note to self: set=set-option; setw=set-window-option; setenv=set-environment;

### Main Settings ### {{{
## Fix glitch with underlined text in Terminal.app and hanging Prompt (iOS)
## From https://github.com/terlar/dotfiles/blob/master/tmux.conf
## Assume http://sourceforge.net/mailarchive/message.php?msg_id=30825085 is origin
set -ag terminal-overrides ",*:XT@"

new-session						# tmux attach makes new, if not running
set -ga update-environment 'DISPLAY'	# Maybe fix DISPLAY?
set -g base-index 1				# Window numbering starts at 1
set -g pane-base-index 1		# Pane numbering starts at 1
setw -g automatic-rename on		# Auto set window title
setw -g aggressive-resize on	# Aggressive windows: For screen size, of diff connections, on diff windows
set -g default-terminal "screen-256color"
set -g history-limit 10000		# Scroll back history
set -g display-panes-time 4000	# Increase show pane time
set -g renumber-windows on		# Make windows auto renumber
### End Main Settings ### }}}

### Key Bindings ### {{{
unbind C-z						# Unbind C-z so I don't suspend, and free for bind
unbind C-b						# Unbind C-b, so I can make C-z the prefix
set -g prefix C-z				# Change prefix key to C-z
bind-key C-z last-window		# Make <prefix>C-z go to last window 
unbind C-a
bind-key C-a send-prefix		# Make <prefix>C-a send C-z literally

## Join windows: <prefix> s, <prefix> j
bind-key j command-prompt -p "join pane from:"  "join-pane -s '%%'"
bind-key s command-prompt -p "send pane to:"  "join-pane -t '%%'"

## URL grab: <prefix> u
bind-key u capture-pane \; save-buffer /tmp/tmux-buffer \; new-window -n "urlview" '$SHELL -c "urlview < /tmp/tmux-buffer"'

## Reload tmux.conf: <prefix> R
bind R source-file ~/.tmux.conf \; display-message "Config reloaded..."

## Zoom: <prefix> Z				# Needs tmux 1.8
#bind Z resize-pane -Z

	### Better Bindings for Splitting ### {{{
	unbind %
#		bind | split-window -h
	bind h split-window -h
	unbind '"'
#		bind - split-window -v
	bind v split-window -v
	### End Splitting Bindings ### }}}

	### Mouse On/Off ### {{{
	## Mouse On by default
	set -g mode-mouse on
	set -g mouse-resize-pane on
	set -g mouse-select-pane on
	set -g mouse-select-window on

	##Toggle mouse on with <prefix>m
	bind m \
		set -g mode-mouse on \;\
		set -g mouse-resize-pane on \;\
		set -g mouse-select-pane on \;\
		set -g mouse-select-window on \;\
		display 'Mouse: ON'

	## Toggle mouse off with <prefix>M
	bind M \
		set -g mode-mouse off \;\
		set -g mouse-resize-pane off \;\
		set -g mouse-select-pane off \;\
		set -g mouse-select-window off \;\
		display 'Mouse: OFF'
	### End Mouse On/Off ### }}}

	### vi Mode for Scroll Back ### {{{
	setw -g mode-keys vi
	unbind [
	bind Escape copy-mode
	unbind p
	bind p paste-buffer
	bind-key -t vi-copy 'v' begin-selection
	bind-key -t vi-copy 'y' copy-selection
	bind-key -t vi-copy Escape cancel
	bind-key -t vi-copy 'Y' copy-end-of-line
	bind-key -t vi-copy 'V' select-line
	### End vi Mode ### }}}

	### Move Window Numbers ### {{{
	## <prefix> Shift left/right
	# Inspired by https://superuser.com/questions/343572/how-do-i-reorder-tmux-windows
	bind-key S-Left swap-window -t -1
	bind-key S-Right swap-window -t +1
	### End Window Numbers ### }}}
### End Key Bindings ### }}}

### Theming Settings ### {{{
## Terminal emulator window title
set -g set-titles on
set -g set-titles-string '#S:#I.#P #W'

## Notifying if other windows has activities
setw -g monitor-activity on
set -g visual-activity on

## Clock
setw -g clock-mode-colour green
setw -g clock-mode-style 24

## Inactive windows
setw -g window-status-format '#[fg=cyan,dim]#I#[fg=blue]:#[default]#W#[fg=grey,dim]#F'

	### Status Bar ### {{{
	set -g status-bg black
	set -g status-fg white
	set -g status-interval 1
	set -g status-left '#[fg=green]#H#[default]'
#	set -g status-right '#[fg=yellow]#(cut -d " " -f 1-4 /proc/loadavg)#[default] #[fg=cyan,bold]%Y-%m-%d %H:%M:%S#[default]'
	set -g status-right '#[fg=cyan,bold]%Y-%m-%d %H:%M#[default]'

		### Bar Bell ### {{{
		#setw -g window-status-bell-attr attributes
		#setw -g window-status-bell-bg colour
		#setw -g window-status-bell-fg colour
		### End Bell ### }}}

		### Bar Content ### {{{
		#setw -g window-status-content-attr attributes
		#setw -g window-status-content-bg colour
		#setw -g window-status-content-fg colour
		### End Content ### }}}

		### Bar Activity ### {{{
		#setw -g window-status-activity-attr attributes
		#setw -g window-status-activity-bg colour
		#setw -g window-status-activity-fg colour
		### End Activity ### }}}

		### Bar Current ### {{{
		## Highlighting the active window in status bar
		#setw -g window-status-current-bg blue
		setw -g window-status-current-format '#[bg=blue,fg=cyan,bold]#I#[bg=blue,fg=cyan]:#[fg=white]#W#[fg=dim]#F'

		### End Current ### }}}

		### Bar Last ### {{{
		#setw -g window-status-last-attr attributes
		#setw -g window-status-last-bg color
		#setw -g window-status-last-fg color
		### End Last ### }}}

	### End Status Bar ### }}}

	### Message/Message Command ### {{{
	set -g message-attr bright
	set -g message-bg cyan
	set -g message-fg white
	set -g message-command-attr bright
	set -g message-command-bg cyan
	set -g message-command-fg white
	### End Message ### }}}

	### Pane Colors ### {{{
	set -g pane-border-fg cyan
	set -g pane-active-border-fg cyan
	### End Pane Colors ### }}}
### End Theming Settings ### }}}

### Need to Figure Out ### {{{

## Log pane to file
#bind P pipe-pane -o "cat >>~/#W.log" \; display "Toggled logging to ~/#W.log"

## can has fit pbcopy on mac, and more??
#set -g default-command "reattach-to-user-namespace -l zsh"

	## Not usable??
	# Alerted window in status bar. Windows which have an alert (bell, activity or content).
#	set-window-option -g window-status-alert-fg red
#	set-window-option -g window-status-alert-bg white


#	### Powerline ### {{{
#		### Deconflict ### {{{
#		set -g status on
#		set -g status-interval 2
#		set -g status-utf8 on
#		set -g status-justify "centre"
#		#set -g status-left-length 60
#		#set -g status-right-length 90
#		set -g status-left "#(~/git/tmux-powerline/status-left.sh)"
#		set -g status-right "#(~/git/tmux-powerline/status-right.sh)"
#		### End Deconflict ### }}}

#	set -g status-left-length 52
#	set -g status-right-length 451
#	set -g status-fg white
#	set -g status-bg colour234
#	set -g window-status-activity-attr bold
#	set -g pane-border-fg colour245
#	set -g pane-active-border-fg colour39
#	set -g message-fg colour16
#	set -g message-bg colour221
#	set -g message-attr bold
#	set -g status-left '#[fg=colour235,bg=colour252,bold] ❐ #S #[fg=colour252,bg=colour238,nobold]⮀#[fg=colour245,bg=colour238,bold] #(whoami) #[fg=colour238,bg=colour234,nobold]⮀'
#	set -g window-status-format "#[fg=white,bg=colour234] #I #W "
#	set -g window-status-current-format "#[fg=colour234,bg=colour39]⮀#[fg=colour25,bg=colour39,noreverse,bold] #I ⮁ #W #[fg=colour39,bg=colour234,nobold]⮀"
#	### End Powerline ### }}}
### End Figure Out ### }}}
